package com.example.mvp.view.video;

import android.os.Environment;

import java.io.File;

/**
 * Created by CHP on 2017/6/20.
 */

public class LKFileOperate {
    private static LKFileOperate mInstance;
    public static LKFileOperate getInstance() {
        if(mInstance == null) {
            mInstance = new LKFileOperate();
        }
        return mInstance;
    }
    /**
     * SD卡是否存在
     */
    public boolean isSDExist() {
        return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    }

    /**
     * 获取sd卡路径
     **/
    public String getSDPath() {
        if (isSDExist()) {
            return Environment.getExternalStorageDirectory().getAbsolutePath();
        } else {
            return null;
        }
    }
    /**
     * 删除文件夹下所有文件,适当放到子线程中执行
     *
     * @param file
     */
    public  void delteFiles(File file) {
        if (file == null || !file.exists()) {return;}
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File f : files) {
                if (!f.isDirectory()) {
                    f.delete();
                }
            }
        } else {
            file.delete();
        }
    }
}
